// ============================================================================
//
// Graph framework by Aurelien Moreau aurelien.moreau@gmail.com
// Modified by Pierre CHATEL chatelp@gmail.com
// Distributed under LGPL
// Copyright (C) Aurelien Moreau, 2008, 2009. All rights reserved
//
// ============================================================================

package com.thalesgroup.graphFramework.collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

public class ArraySet<T> extends ArrayList<T> implements Set<T>, Cloneable {

	private static final String ELEMENT_DELIMITER = ","; //$NON-NLS-1$
	private static final String CLOSE_SET_DELIMITER = "}"; //$NON-NLS-1$
	private static final String OPEN_SET_DELIMITER = "{"; //$NON-NLS-1$
	private static final long serialVersionUID = -2883629001479547842L;

	public ArraySet() {
		super();
	}

	public ArraySet(final Collection<? extends T> c) {
		super(c);
	}

	public ArraySet(final int initialCapacity) {
		super(initialCapacity);
	}

	@Override
	public String toString() {
		final StringBuffer buffer = new StringBuffer();

		buffer.append(OPEN_SET_DELIMITER);
		for (final Iterator<T> i = iterator(); i.hasNext();) {
			buffer.append(i.next());
			if (i.hasNext()) {
				buffer.append(ELEMENT_DELIMITER);
			}
		}
		buffer.append(CLOSE_SET_DELIMITER);
		return buffer.toString();
	}

	@Override
	public Object clone() {
		super.clone();
		return new ArraySet<T>(this);
	}

}
